package org.fioma.general;

import java.util.ArrayList;

public class MatchLog {

	private static ArrayList<MatchLog> pool = new ArrayList<MatchLog>(400);
	private static int nextObj = 0;

	int matePairStart;
	int length;
	int matePairSize;
	int validReadStart;
	int distanceToLeaf;
	int mismatchesToleaf;

	private MatchLog(int matePairStart, int length, int matePairSize, int validReadStart, int distanceToLeaf, int mismatchesToleaf) {
		this.matePairStart = matePairStart;
		this.length = length;
		this.validReadStart = validReadStart;
		this.distanceToLeaf = distanceToLeaf;
		this.mismatchesToleaf = mismatchesToleaf;
		this.matePairSize = matePairSize;
	}

	public static MatchLog getInstance(int matePairStart, int length, int matePairSize, int validReadStart, int distanceToLeaf, int mismatchesToleaf) {
		if (nextObj >= pool.size()) {
			addValuesToPool(100);
		}
		MatchLog ret = pool.get(nextObj);
		nextObj++;
		ret.matePairStart = matePairStart;
		ret.length = length;
		ret.validReadStart = validReadStart;
		ret.distanceToLeaf = distanceToLeaf;
		ret.mismatchesToleaf = mismatchesToleaf;
		ret.matePairSize = matePairSize;
		return ret;
	}

	public static MatchLog getInstance(String matePairStart, String length, int matePairSize, String validReadStart, String distanceToLeaf,
			String mismatchesToleaf) {
		if (nextObj >= pool.size()) {
			addValuesToPool(100);
		}
		MatchLog ret = pool.get(nextObj);
		nextObj++;
		ret.matePairStart = Integer.parseInt(matePairStart);
		ret.length = Integer.parseInt(length);
		ret.validReadStart = Integer.parseInt(validReadStart);
		ret.distanceToLeaf = Integer.parseInt(distanceToLeaf);
		ret.mismatchesToleaf = Integer.parseInt(mismatchesToleaf);
		ret.matePairSize = matePairSize;
		return ret;
	}

	public int getMatePairStart() {
		return matePairStart;
	}

	public int getMatePairSize() {
		return matePairSize;
	}

	public int getMatePairEnd() {
		return matePairStart + length - 1;
	}

	public int getLength() {
		return length;
	}

	public int getValidReadStart() {
		return validReadStart;
	}

	public int getDistanceToLeaf() {
		return distanceToLeaf;
	}

	public int getMismatchesToleaf() {
		return mismatchesToleaf;
	}

	public static void freePool() {
		nextObj = 0;
	}

	public static void addValuesToPool(int qtty) {
		for (int i = 0; i < qtty; i++) {
			pool.add(new MatchLog(0, 0, 0, 0, 0, 0));
		}
	}

}
